'use strict';

const Service = require('egg').Service;
const captcha = require('svg-captcha');


// 定义自己的业务处理模块 并继承 Controller 类名尽量和文件名保持一致
class HeollService extends Service {
  // 方法前一定需要 asyunc 修饰
  async say() {
    return 'heoll world 付璐广';
  }

  async login(logininfo) {

    const userinfo = {
      username: 'root',
      password: '123456',
    };
    console.log(logininfo);
    var code = this.ctx.session.verifycode
    console.log(code);
    if (logininfo.username === userinfo.username && logininfo.password === userinfo.password && logininfo.code === code) {
      return true;
    }
    return false;

  }


 
   // 生成验证码
   async verifycode(){
    let svg = captcha.create({
      size:4,
      color:true,
      inverse: false,
      noise:0,
      // width: 85,
      // height:40,
      background: '#DEE1E6'
    });

    console.log('生成验证码:',svg.text);
    // 将验证码存放在session key:verifycode
    // 将验证码转为小写
     this.ctx.session.verifycode = svg.text.toLowerCase();
    return svg;
  }
}
// 导出业务模块
module.exports = HeollService;
